//go:build wireinject

package main

import (
	"github.com/google/wire"
	repository2 "webook/interactive/repository"
	cache2 "webook/interactive/repository/cache"
	dao2 "webook/interactive/repository/dao"
	service2 "webook/interactive/service"
	"webook/internal/events/article"
	"webook/internal/repository"
	"webook/internal/repository/cache"
	"webook/internal/repository/dao"
	"webook/internal/service"
	"webook/internal/web"
	ijwt "webook/internal/web/jwt"
	"webook/ioc"
)

var interactiveSvcSet = wire.NewSet(dao2.NewGORMInteractiveDao, cache2.NewRedisInteractiveCache,
	repository2.NewCachedInteractiveRepository, service2.NewInteractiveService)

var rankingSvcSet = wire.NewSet(
	cache.NewRankingRedisCache,
	repository.NewCachedRankingRepository,
	service.NewBatchRankingService,
)

//var jobProviderSet = wire.NewSet(
//	service.NewCronJobService,
//	repository.NewPreemptJobRepository,
//	dao.NewGORMJobDAO)

func InitWebServer() *App {
	wire.Build(
		//第三方依赖
		ioc.InitRedis, ioc.InitDB, ioc.InitLogger,
		ioc.InitSaramaClient, ioc.InitSyncProducer,
		ioc.InitRlockClient, ioc.InitEtcd,
		ioc.InitReward,
		//dao
		dao.NewUserDAO, dao.NewArticleORMDAO,
		//events
		article.NewSaramaSyncProducer,
		//events.NewInteractiveReadEventConsumer,
		ioc.InitConsumers,
		//self_cache
		cache.NewUserCache, cache.NewCodeCache, cache.NewArticleRedisCache,
		//repository
		repository.NewCacheUserRepository, repository.NewCodeRepository, repository.NewCacheArticleRepository,
		//service
		ioc.InitSMSService, ioc.InitWechatService,
		service.NewUserService, service.NewCodeService, service.NewArticleService,
		//handler
		ijwt.NewRedisJWTHandler,
		web.NewUserHandler,
		web.NewOAuth2WechatHandler,
		web.NewArticleHandler,
		ioc.InitGinMiddlewares, ioc.InitWebServer,
		//按业务线注册
		//interactiveSvcSet,
		ioc.InitIntrClient,
		rankingSvcSet,

		//定时任务
		ioc.InitJobs,
		ioc.InitRankingJob,

		wire.Struct(new(App), "*"),
	)
	return new(App)
}

//func InitJobScheduler() *job.Scheduler {
//	wire.Build(jobProviderSet, thirdPartySet, job.NewScheduler)
//	return &job.Scheduler{}
//}
